<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
参数：
pageHolderName：PageHolder在requestScope里面的名字，默认为"pageHolder"。
--%>
<%
	String pageHolderName=request.getParameter("pageHolderName");
	if(pageHolderName==null){
		pageHolderName="pageHolder";
	}
	pageContext.setAttribute("pageHolder",request.getAttribute(pageHolderName));
%>
<script>
	function go(my,params,max)
	{
		my.disabled=true;
		var page=document.getElementById("page_index").value;
		var reg = /^\d+$/;
		
		if(page.match(reg))
			{
				
				if(page>max)
					{
					alert("不能超过最大页数");
					}
				else
					{
	        	var pageIndexKey ="${pageHolder.pageIndexKey}";
	        	location.href="?"+pageIndexKey+"="+page+params;
					}
	      	
			}
		else 
			{
			alert("只能输入数字");
			}
	}
</script>
<div>总数：${pageHolder.rowCount}
  <c:choose>
    <c:when test="${pageHolder.firstPage}">[首页] [上一页]</c:when>
    <c:otherwise>
      <c:url var="firstPage" value="">
        <c:param name="${pageHolder.pageIndexKey}" value="1"/>
      </c:url>
      <c:url var="previousPage" value="">
        <c:param name="${pageHolder.pageIndexKey}" value="${pageHolder.pageIndex-1}"/>
      </c:url>
      [<a href="${firstPage}${pageHolder.params}">首页</a>] [<a href="${previousPage}${pageHolder.params}">上一页</a>]</c:otherwise>
  </c:choose>
  <c:choose>
    <c:when test="${pageHolder.lastPage}">[下一页] [末页]</c:when>
    <c:otherwise>
      <c:url var="nextPage" value="">
        <c:param name="${pageHolder.pageIndexKey}" value="${pageHolder.pageIndex+1}"/>
      </c:url>
      <c:url var="lastPage" value="">
        <c:param name="${pageHolder.pageIndexKey}" value="${pageHolder.pageCount}"/>
      </c:url>
      [<a href="${nextPage}${pageHolder.params}">下一页</a>] [<a href="${lastPage}${pageHolder.params}">末页</a>]</c:otherwise>
  </c:choose>
  第${pageHolder.pageIndex}/${pageHolder.pageCount}页
  
  <!--当页数小于100时，使用下拉框的方式 -->
  <c:if test="${pageHolder.pageCount<=100}">
  
  <select onchange="this.disabled=true;location.href=this.options[this.selectedIndex].value;">
    <c:forEach begin="1" end="${pageHolder.pageCount}" var="count">
      <c:url var="pageIterater" value="">
        <c:param name="${pageHolder.pageIndexKey}" value="${count}"/>
      </c:url>
      <c:choose>
        <c:when test="${count==pageHolder.pageIndex}">
          <option value="${pageIterater}${pageHolder.params}" selected="selected">${count}</option>
        </c:when>
        <c:otherwise>
          <option value="${pageIterater}${pageHolder.params}">${count}</option>
        </c:otherwise>
      </c:choose>
    </c:forEach>
  </select>
  
  </c:if>
  
  <!--当页数小于100时，使用文本框输入的方式 -->
  <c:if test="${pageHolder.pageCount>100}">
  	
  	<input type="text" id="page_index" size="5"/>
  	<a href="javascript:go(this,'${pageHolder.params}',${pageHolder.pageCount})">跳转</a> &nbsp;
  </c:if>
  
  
  <a href="javascript:location.reload()">刷新</a></div>
